package com.interceptor;

import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ClassName: LoginInterceptor  
 * @Description:登录拦截器
 */
public class LoginInterceptor implements HandlerInterceptor{
	
//	@Override
//	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
//			throws Exception {
//		//拦截器拦截所有请求，除了logins请求之外
//		String uri = request.getRequestURI();//获取请求的uri
//		System.out.println(uri);
//		//判断获取的请求路径是否包含登录的路径,如果是，不拦截
//		if(uri.indexOf("/adminlogin")>0){
//			return true;
//		}else{
//			//如果在session里面有对象，那么也可以访问
//			HttpSession session=request.getSession();
//			Object object = session.getAttribute("admin");
//			if(object !=null){
//				return true;
//			}
//			//如果没有对象，重定向到登录
//			response.sendRedirect("login.jsp");
//			return false;
//		}
//	}
//	
//	@Override
//	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
//			ModelAndView modelAndView) throws Exception {
//		System.out.println("postHandle方法执行");
//	}
//	
//	@Override
//	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
//			throws Exception {
//		System.out.println("afterCompletion方法执行");
//	}


}
